package config

import (
	"go.uber.org/zap"
	"gopkg.in/yaml.v3"
	"os"
)

type AgentConfig struct {
	RpcServerAddr         string `yaml:"rpc_server_addr"`
	RpcCallTimeOutSeconds int    `yaml:"rpc_call_time_out_seconds"`
	HttpAddr              string `yaml:"http_addr"`
	LogLevel              string `yaml:"log_level"`
	LogFilePath           string `yaml:"log_file_path"`

	InfoCollectC *InfoCollect `yaml:"info_collect"`
	JobExecC     *JobExec     `yaml:"job_exec"`
	HostName     string       `yaml:"-"`
	LocalIp      string       `yaml:"-"`
	Logger       *zap.Logger  `yaml:"-"` // 不是配置文件提供的，而是 共用配置文件这个结构体，在生成完logger后设置的
}

// 根据io read读取配置文件后的字符串解析yaml
func LoadAgent(filename string) (*AgentConfig, error) {
	cfg := &AgentConfig{}

	content, err := os.ReadFile(filename)
	if err != nil {
		return nil, err
	}
	err = yaml.Unmarshal(content, cfg)
	if err != nil {
		return nil, err
	}

	// 加载配置文件的时候就塞进去

	return cfg, err

}

type InfoCollect struct {
	Enable             bool `yaml:"enable"`
	RunIntervalSeconds int  `yaml:"run_interval_seconds"`
}

type JobExec struct {
	Enable             bool   `yaml:"enable"`
	RunIntervalSeconds int    `yaml:"run_interval_seconds"`
	MetaDir            string `yaml:"meta_dir"`
	ExecTimeoutSeconds int    `yaml:"execTimeoutSeconds"`
	PythonBinPath      string `yaml:"python_bin_path"`
	BashBinPath        string `yaml:"bash_bin_path"`
}
